﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FeedBack.Models;

namespace FeedBack.Controllers
{
    public class ContactController : Controller
    {
        ContactRepository contactRepository = new ContactRepository();
        //
        // GET: /Contac/

        public ActionResult Index()
        {
            var contact = contactRepository.FindAllContact().ToList();
            return View(contact);
        }

        public ActionResult Create()
        {
            Contact c = new Contact();

            return View(c);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(Contact c)
        {
            contactRepository.Add(c);
            contactRepository.Save();

            return RedirectToAction("Index");
        }

        public ActionResult Delete(int id)
        {
            var contact = contactRepository.GetUser(id);

            if (contact == null) return View("NotFount");

            return View(contact);

        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(int id, string confirm)
        {
            contactRepository.Delete(contactRepository.GetUser(id));
            contactRepository.Save();
            return RedirectToAction("Index");

        }
    }
}
